package com.freewater.library.lending.book.presentation.request;

import com.freewater.library.lending.book.application.command.CancelReserveBookInstanceCommand;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import org.apache.commons.lang3.Validate;

@Getter
public class CancelReserveBookInstanceRequest {

    @Parameter(description = "二维码")
    @NotBlank(message = "二维码不能为空")
    private String qrCode;

    @Parameter(description = "读者Id")
    @NotNull(message = "读者Id不能为空")
    private Long readerId;

    @Parameter(description = "取消原因")
    @NotBlank(message = "取消原因不能为空")
    private final String reason;

    public CancelReserveBookInstanceRequest(String qrCode, Long readerId, String reason) {
        Validate.notBlank(qrCode, "二维码不能为空");
        Validate.notNull(readerId, "读者ID不能为空");
        Validate.notBlank(reason, "取消原因不能为空");
        this.qrCode = qrCode;
        this.readerId = readerId;
        this.reason = reason;
    }

    public CancelReserveBookInstanceCommand toCommand() {
        return new CancelReserveBookInstanceCommand(this.qrCode, this.readerId, this.reason);
    }
}
